// index.js
import util from '../../../utils/util.js';
const { $Message } = require('../../../dist/base/index');
import { $wuxDialog } from '../../../weappdist/index'
var app = getApp();
var logincontent = '尚未登录，请先登录吗？';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    username:'',
    userimg:'',
    visible3: false,
    islogin:false,
    user: '',
    actions3: [
      {
        name: '退出登录',
        color: '#2d8cf0',
      },
      {
        name: '取消'
      }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      // title: util.pageTitle.member
    });
  },

  

  // 登出账号
  logout() {
    var that = this;
    wx.showModal({
      title: '提醒',
      content: '确定退出登录吗？',
      success: function (eci) {
        if (eci.confirm) {
          // wx.setStorageSync('user_info', '');
          util.saveData('userinfo','');
          that.setData({
            username: '登录',
            userimg: '/images/appIcon.png',
            islogin:false,
          });
        } else {

        }
      }
    });
    // util.showToast('退出登录成功', 'success');
    // setTimeout(function(){
    //   wx.switchTab({
    //     url: '/pages/index/index'
    //   });
    // }, 1500);
  },

  // 获取订单统计
  // ecapi.order.subtotal
 

  

  // jump
  myschedulelist() {
    wx.navigateTo({
      url: '../../schedule/schedulelist/schedulelist'
    });
  },
  // jump
 
  // jump
  

  // 设置会员信息
  // setUserInfo() {
  //   let user = wx.getStorageSync('user');
  //   this.setData({
  //     userInfo: user
  //   });
  // },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  login:function(){
    if(!this.data.islogin)
    {
    wx.navigateTo({
      url: '../../auth/login/login'
    })
    }
  },

  member_about: function () {
    // if (!this.data.islogin) {
      wx.navigateTo({
        url: '../../util/webview/webview?url=https://www.autorepairehelper.cn/noticeboard/about'
      })
    // }
  },
  
  intro:function(){
    wx.navigateTo({
      url: '../../util/webview/webview?url=https://www.autorepairehelper.cn/noticeboard/xcxsysc'
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.bindUserTap();
    // this.getOrderTotal();
    // var usetinfo = wx.getStorageSync("user_info");
    var usetinfo = util.getData("userinfo");

    if (usetinfo == "") {
      this.setData({
        username: '登录',
        userimg: '/images/appIcon.png',
        islogin: false,
      });

    } else {
      this.setData({
        username: usetinfo.name,
        userimg: usetinfo.headurl,
        islogin: true,
      });
    }
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  mycar: function () {
    if (this.data.islogin) {
      wx.navigateTo({
        url: '../../mycar/list/list'
      })
    }else{
      var that = this;
      wx.showModal({
        title: '提醒',
        content: logincontent,
        success: function (eci) {
          if (eci.confirm) {
            wx.navigateTo({
              url: '../../auth/login/login'
            })
          } else {
          }
        }
      });
    }
  },

  myschedulelist: function () {
    if (this.data.islogin) {
      wx.navigateTo({
        url: '../../schedule/schedulelist/schedulelist'
      })
    }else{
      var that = this;
      wx.showModal({
        title: '提醒',
        content: logincontent,
        success: function (eci) {
          if (eci.confirm) {
            wx.navigateTo({
              url: '../../auth/login/login'
            })
          } else {
          }
        }
      });
    }
  },

  myOrder: function () {
    if (this.data.islogin) {
    wx.navigateTo({
      url: '../../workorder/workorderlist/workorderlist'
    });
    }else{
      var that = this;
      wx.showModal({
        title: '提醒',
        content: logincontent,
        success: function (eci) {
          if (eci.confirm) {
            wx.navigateTo({
              url: '../../auth/login/login'
            })
          } else {
          }
        }
      });
    }
  },
  
  myFav: function () {
    if (this.data.islogin) {
      wx.navigateTo({
        url: '../../carstore/favlist/list'
      });
    } else {
      var that = this;
      wx.showModal({
        title: '提醒',
        content: logincontent,
        success: function (eci) {
          if (eci.confirm) {
            wx.navigateTo({
              url: '../../auth/login/login'
            })
          } else {
          }
        }
      });
    }
  },
  
  
});